﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class TransactionDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadAccountNumber();
            LoadAccountInfor();
        }
    }

    private void LoadAccountInfor()
    {
        if (Request.QueryString["ACN"] != null)
        {
            String ACN = Request.QueryString["ACN"];
            localhost.Service SvBank = new localhost.Service();
            DataTable dt = new DataTable();
            dt = SvBank.AccountDetail(ACN);

            //set
            lblAccountName.Text = dt.Rows[0]["Owner"].ToString();
            lblAddress.Text = dt.Rows[0]["Address"].ToString();
            lblAccountNumber.Text = dt.Rows[0]["AccountNumber"].ToString();
            lblBalance.Text = String.Format("{0:0,0}", Convert.ToDecimal(dt.Rows[0]["Balance"].ToString()));
            lblCMTORHC.Text = dt.Rows[0]["CMTORHC"].ToString();
            lblMoneyType.Text = dt.Rows[0]["MoneyType"].ToString();
            lblDateOpen.Text = dt.Rows[0]["OpenDatetime"].ToString();
            lblLastTransaction.Text = dt.Rows[0]["LastTransaction"].ToString();
            lblAccountType.Text = SvBank.AccountTypeName(Convert.ToInt32(dt.Rows[0]["AccountTypeID"].ToString())).Rows[0]["AccountTypeName"].ToString();
        }
        else
        {
            String ACN = ddlAccount.SelectedValue;
            localhost.Service SvBank = new localhost.Service();
            DataTable dt = new DataTable();
            dt = SvBank.AccountDetail(ACN);

            //set
            lblAccountName.Text = dt.Rows[0]["Owner"].ToString();
            lblAddress.Text = dt.Rows[0]["Address"].ToString();
            lblAccountNumber.Text = dt.Rows[0]["AccountNumber"].ToString();
            lblBalance.Text = String.Format("{0:0,0}", Convert.ToDecimal(dt.Rows[0]["Balance"].ToString()));
            lblCMTORHC.Text = dt.Rows[0]["CMTORHC"].ToString();
            lblMoneyType.Text = dt.Rows[0]["MoneyType"].ToString();
            lblDateOpen.Text = dt.Rows[0]["OpenDatetime"].ToString();
            lblLastTransaction.Text = dt.Rows[0]["LastTransaction"].ToString();
            lblAccountType.Text = SvBank.AccountTypeName(Convert.ToInt32(dt.Rows[0]["AccountTypeID"].ToString())).Rows[0]["AccountTypeName"].ToString();
        }
    }

    private void LoadAccountNumber()
    {
        localhost.Service SvBank = new localhost.Service();
        ddlAccount.DataSource = SvBank.ListAccount("AA19111990");
        ddlAccount.DataBind();

        if (Request.QueryString["ACN"] != null)
        {
            String ACN = Request.QueryString["ACN"];
            int i = 0;
            foreach (ListItem item in ddlAccount.Items)
            {
                i++;
                if (item.Value == ACN)
                {
                    ddlAccount.SelectedIndex = i - 1;
                }
            }
        }
    }
    protected void btnViewDetail_Click(object sender, EventArgs e)
    {
        String ACN = ddlAccount.SelectedValue;
        localhost.Service SvBank = new localhost.Service();
        DataTable dt = new DataTable();
        dt = SvBank.AccountDetail(ACN);

        //set
        lblAccountName.Text = dt.Rows[0]["Owner"].ToString();
        lblAddress.Text = dt.Rows[0]["Address"].ToString();
        lblAccountNumber.Text = dt.Rows[0]["AccountNumber"].ToString();
        lblBalance.Text = String.Format("{0:0,0}", Convert.ToDecimal(dt.Rows[0]["Balance"].ToString()));
        lblCMTORHC.Text = dt.Rows[0]["CMTORHC"].ToString();
        lblMoneyType.Text = dt.Rows[0]["MoneyType"].ToString();
        lblDateOpen.Text = dt.Rows[0]["OpenDatetime"].ToString();
        lblLastTransaction.Text = dt.Rows[0]["LastTransaction"].ToString();
        lblAccountType.Text = SvBank.AccountTypeName(Convert.ToInt32(dt.Rows[0]["AccountTypeID"].ToString())).Rows[0]["AccountTypeName"].ToString();
    }
    protected void btnViewTransaction_Click(object sender, EventArgs e)
    {
        DateTime begindate = Convert.ToDateTime(txtBgDate.Text);
        DateTime enddate = Convert.ToDateTime(txtEndDate.Text);
        String ACN = ddlAccount.SelectedValue;
        localhost.Service SvBank = new localhost.Service();
        grvTransaction.DataSource = SvBank.ViewTransactionByDate(begindate,enddate,ACN);
        grvTransaction.DataBind();
    }
}
